/**
 * 
 */
package com.gr.staffpm.widget.calendar;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;


/**
 * @author Graham Rhodes 7 Jan 2011 10:26:42
 */
public class MonthLabel extends Panel {

    private static final long serialVersionUID = 1L;
    private final int currMonth;
    private final int month;
    private final Date date;

    public MonthLabel(String id, Calendar cal, int month) {
        this(id, cal, month, false);
    }

    public MonthLabel(String id, Calendar cal, int month, boolean monthChange) {
        super(id);
        this.currMonth = cal.get(Calendar.MONTH);
        this.month = month;
        this.date = cal.getTime();

        String monthDateLabel = "";
        if (monthChange)
            monthDateLabel = cal.getDisplayName(Calendar.MONTH, Calendar.SHORT, getLocale()) + " " + String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
        else
            monthDateLabel = String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
        add(new Label("monthDateLabel", monthDateLabel));
    }

    @Override
    protected void onComponentTag(ComponentTag tag) {
        super.onComponentTag(tag);

        SimpleDateFormat df = new SimpleDateFormat("dd.MMM.yyyy");

        String classes = "cal-date-label";
        if (currMonth != month) {
            classes = "cal-date-label cal-date-non-month";
        }
        if (df.format(date).equals(df.format(Calendar.getInstance().getTime()))) {
            classes += " cal-today";
        }
        tag.getAttributes().put("class", classes);
    }
}
